home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / fortran / f2c-stab.9 / f2c-stab / f2c-stabs / fts-f-trim-decls < prev    next >
Encoding:
AWK Script  |  1996-02-11  |  2.9 KB  |  131 lines

  1. #!/usr/bin/awk -f
  2. # -*- awk -*-
  3. #
  4. # $Header: /usr/bfr/src/test/RCS/fts-f-trim-decls,v 1.1 1995/01/18 17:39:14 abel Exp $
  5. #
  6. #********************************************
  7. #
  8. # convert character strings FORTRAN decls to STRINGs
  9. #
  10. # input must not contain comments, splitted lines and multiple decls
  11. # NOTE: doesn't handle thigs more complicated than char strings
  12. #
  13. #********************************************
  14. #
  15. # Written by Alexander L. Belikoff, 1994
  16. # Copyright (C)1994 Alexander L. Belikoff
  17. #
  18. # This program is free software; you can redistribute it and/or modify
  19. # it under the terms of the GNU General Public License as published by
  20. # the Free Software Foundation; either version 2 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. # GNU General Public License for more details.
  27. #
  28. #********************************************
  29. #
  30. # $Log: fts-f-trim-decls,v $
  31. # Revision 1.1  1995/01/18  17:39:14  abel
  32. # Initial revision
  33. #
  34. #
  35. #********************************************
  36.  
  37.  
  38. # CHARACTER*33 A  ->  %STRING% A(33)
  39. # CHARACTER*(*) A  ->  %STRING% A(*)
  40.  
  41. $0 ~ /^      +CHARACTER[ \t]*\*[ \t]*[0-9]+[ \t]/ ||
  42. $0 ~ /^      +CHARACTER[ \t]*\*[ \t]*\([ \t]*\*[ \t]*\)[ \t]/ {
  43.     
  44.     res = $0
  45.     gsub(/[ \t]*\*[ \t]*/, "*", res)
  46.     gsub(/[ \t]*\([ \t]*/, "(", res)
  47.     gsub(/[ \t]*\)[ \t]*/, ") ", res)
  48.     res = substr(res, index(res, "*") + 1)
  49.     len = res
  50.  
  51.     if (len ~ /^\(\*\) .*$/) {
  52.         res = substr(res, index(res, ")") + 1)
  53.         len = "*"
  54.     }
  55.     else {
  56.         res = substr(res, index(res, " "))
  57.         sub(/[ \t]+.*$/, "", len)
  58.     }
  59.  
  60.     len = "(" len ")"
  61.  
  62.  
  63.     res = "      %STRING%" res
  64.     gsub("\,", len ", ", res)
  65.     res = res len
  66.  
  67.     print res
  68.     next
  69. }
  70.  
  71.  
  72. # CHARACTER A*(*)  ->  %STRING% A(*)
  73.  
  74. $0 ~ /^      +CHARACTER/ && $0 ~ /\*[ \t]*\([ \t]*\*[ \t]*\)/ {
  75.     
  76.     res = $0
  77.     gsub(/[ \t]*\*[ \t]*/, "*", res)
  78.     gsub(/[ \t]*\([ \t]*/, "(", res)
  79.     gsub(/[ \t]*\)[ \t]*/, ") ", res)
  80.     sub("CHARACTER", "%STRING%", res)
  81.     gsub(/\*\(\*\)/, "(*)", res)
  82.  
  83.     print res
  84.     next
  85. }
  86.  
  87.  
  88. # CHARACTER A*NNN  ->  %STRING% A(NNN)
  89.  
  90. $0 ~ /^      +CHARACTER[ \t]*[^\*]/ &&
  91. $0 ~ /\*[ \t]*[0-9]/ {
  92.     
  93.     res = $0
  94.     gsub(/\*/, " * ", res)
  95.     gsub(/,/, " , ", res)
  96.  
  97.     res = substr(res, index(res, "C"))
  98.     i1 = index(res, " ")
  99.  
  100.     npc = split(substr(res, i1), pieces, " ")
  101.  
  102.     i = 1
  103.  
  104.     while (i <= npc) {
  105.         typ = "      CHARACTER "
  106.         res = pieces[i]
  107.         i++
  108.  
  109.         if (index(pieces[i], "*")) {
  110.             res = res "(" pieces[i+1] ")"
  111.             typ = "      %STRING% "
  112.             i += 2
  113.         }
  114.  
  115.         if (index(pieces[i], ",")) {
  116.             res = res pieces[i]
  117.             i++
  118.         }
  119.  
  120.         print typ res
  121.     }
  122.  
  123.     next
  124. }
  125.  
  126.  
  127. { print }
  128.  
  129. # end of $Source: /usr/bfr/src/test/RCS/fts-f-trim-decls,v $
  130.